//
// Created by zhengbo on 23-4-18.
//

#ifndef VISUALIZATION_TOOL_OBJECTDETECTION_H
#define VISUALIZATION_TOOL_OBJECTDETECTION_H

#include "RenderObject.h"

struct BBox {
    Vector3f centerPoint;
    Vector3f boxSize;

    std::vector<Vector3f> GetCorners() const;

    std::vector<std::pair<Vector3f, Vector3f>> GetEdges() const;
};

class ObjectDetection : public RenderObject {
public:
    ObjectDetection(std::vector<BBox> boxes);

    virtual void Update() override;

    virtual void Render() override;

    virtual void InitBuffer() override;

    virtual void ReleaseBuffer() override;

private:
    uint32_t mVbo = 0;
    std::vector<BBox> mBoxes;
};

void ObjectDetection::Update() {}

void ObjectDetection::Render() {
    for (auto box : mBoxes) {
        glBegin(GL_LINES);
        glColor3f(1.0, 0.0, 0.0);
        auto boxEdges = box.getEdges();
        for (const auto& edge : boxEdges) {
            glVertex3f(edge.first.x(), edge.first.y(), edge.first.z());
            glVertex3f(edge.second.x(), edge.second.y(), edge.second.z());
        }
        glEnd();
    }
}

void ObjectDetection::InitBuffer() {
    if (mVbo == 0) {
        glGenBuffers(1, &mVbo);
    }
}

void ObjectDetection::ReleaseBuffer() {
    if (mVbo != 0) {
        glDeleteBuffers(1, &mVbo);
        mVbo = 0;
    }
}

#endif //VISUALIZATION_TOOL_OBJECTDETECTION_H
